package com.isunland.managesystem.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.LeaseMainList;
import com.isunland.managesystem.utils.MyDateUtil;
import com.isunland.managesystem.utils.MyUtils;
import java.util.ArrayList;
import java.util.List;

public class LeaseOrderAdapter<T> extends BaseAdapter {

  private List<T> objects = new ArrayList<>();

  private Context context;
  private LayoutInflater layoutInflater;

  //private Callback mCallback;
  public LeaseOrderAdapter(Context context, ArrayList<T> objects) {
    this.context = context;
    this.layoutInflater = LayoutInflater.from(context);
    this.objects = objects;
    //this.mCallback=callback;
  }

  @Override public int getCount() {
    return objects.size();
  }

  @Override public T getItem(int position) {
    return objects.get(position);
  }

  @Override public long getItemId(int position) {
    return position;
  }

  @Override public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
      convertView = layoutInflater.inflate(R.layout.adapter_appointment_order, parent, false);
      convertView.setTag(new ViewHolder(convertView));
    }

    initializeViews(getItem(position), (ViewHolder) convertView.getTag());

    return convertView;
  }

  private void initializeViews(T object, ViewHolder holder) {
    LeaseMainList item = (LeaseMainList) object;
    holder.tvOrderNo.setText(context.getString(R.string.orderNoWithHoder, item.getLeaseNo()));
    //holder.tvBottomRight.setText("￥" + String.valueOf(item.getOperationCost()));
    holder.tvOperationDesc.setText(item.getLeaseText());
    holder.tvOrderTime.setText(
        MyDateUtil.parseDateToString(MyDateUtil.stringToDate(item.getLeaseDate())));
    MyUtils.switchShadowStutus(context, holder.tvPlanStatus, item.getDataStatus());//数据状态
    holder.tvPlanStatus.setText(item.getDataStatusName());
    //MyUtils.switchDataStutus(context, holder.tvPlanStatus, item.getDataStatus());
    //holder.tvCancel.setTag(position);
    //holder.tvReminder.setTag(position);

  }

  protected class ViewHolder {
    @BindView(R.id.tv_orderNo) TextView tvOrderNo;
    @BindView(R.id.tv_operationDesc) TextView tvOperationDesc;
    @BindView(R.id.tv_bottomLeft) TextView tvOrderTime;
    //@BindView(R.id.tv_money)
    //TextView tvBottomRight;
    //@BindView(R.id.ll_planStatus)
    //LinearLayout llPlanStatus;
    @BindView(R.id.tv_planStatus) TextView tvPlanStatus;
    @BindView(R.id.iv_logo) ImageView ivLogo;

    //@BindView(R.id.tv_cancel)
    //TextView tvCancel;
    //@BindView(R.id.tv_reminder)
    //TextView tvReminder;

    ViewHolder(View view) {
      ButterKnife.bind(this, view);
      ivLogo.setImageResource(R.drawable.order_lease);
    }
  }

  public interface Callback {
    void click(View v);
  }
}
